package com.dein.music.service.impl;

import com.dein.music.dao.MusicAccumulationDao;
import com.dein.music.model.Music;
import com.dein.music.service.MusicAccumulationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("musicAccumulationService")
public class MusicAccumulationServiceImpl implements MusicAccumulationService{
    protected MusicAccumulationDao musicAccumulationDao;



    @Autowired
    @Qualifier("musicAccumulationDao")
    public void setMusicAccumulationDao(MusicAccumulationDao musicAccumulationDao) {
        this.musicAccumulationDao = musicAccumulationDao;
    }


    @Override
    public List<Music> getAccumulationMusic(Long userId,Integer limit,Integer start) {
        try{
            return musicAccumulationDao.getAccumulationMusic(userId,limit,start);
        }catch (Exception e){
            e.printStackTrace();
            return  null;
        }
    }

    @Override
    public boolean addAccumulationMusic(Long userId, Long musicId) {
        try{
            musicAccumulationDao.addAccumulationMusic(userId,musicId);
        }catch (Exception e){
            e.printStackTrace();
            return  false;
        }
        return true;
    }

    @Override
    public Integer countAccumulationMusic(Long userId) {
        try{
            return musicAccumulationDao.countAccumulationMusic(userId);
        }catch (Exception e){
            e.printStackTrace();
            return  null;
        }
    }

    @Override
    public boolean accumulationMusicExist(Long userId, Long musicId) {
        try {
            if(musicAccumulationDao.accumulationMusicExist(userId,musicId)>0)
                return  true;
            else
                return  false;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
